package org.dromara.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.comm.domain.AsLeaveIdle;
import org.dromara.comm.mapper.AsLeaveIdleMapper;
import org.dromara.community.entity.AsSpaceReservation;
import org.dromara.community.entity.dto.AsLeaveIdleDTO;
import org.dromara.community.entity.dto.AsSpaceReservationDTO;
import org.dromara.community.mapper.AsSpaceReservationMapper;
import org.dromara.community.service.AsSpaceReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AsSpaceReservationServiceimpl extends ServiceImpl<AsSpaceReservationMapper, AsSpaceReservation> implements AsSpaceReservationService {


    @Autowired
    private AsSpaceReservationMapper asSpaceReservationMapper;

    @Autowired
    private AsLeaveIdleMapper asLeaveIdleMapper;


    @Override
    public List<AsSpaceReservationDTO> getAllReservations() {
        // 创建查询条件构造器
        QueryWrapper<AsSpaceReservation> queryWrapper = new QueryWrapper<>();
        // 你可以在这里添加更多的查询条件，例如
        // queryWrapper.eq("status", "active");

        // 从数据库中获取所有符合条件的实体对象
        List<AsSpaceReservation> entities = asSpaceReservationMapper.selectList(queryWrapper);

        // 将实体对象转换为 DTO 对象
        return entities.stream()
            .map(entity -> new AsSpaceReservationDTO(
                entity.getId(),
                entity.getActivityName(),
                entity.getSpaceAddress(),
                entity.getSpatialImage()))
            .collect(Collectors.toList());
    }

    @Override
    public List<AsLeaveIdleDTO> getAll() {
        QueryWrapper<AsLeaveIdle> queryWrapper = new QueryWrapper<>();
        // 如果需要，可以在这里添加更多查询条件

        // 查询所有记录
        List<AsLeaveIdle> entities = asLeaveIdleMapper.selectList(queryWrapper);

        // 将查询结果映射到 DTO 对象
        return entities.stream()
            .map(entity -> new AsLeaveIdleDTO(
                entity.getId(),
                entity.getDescription(),
                entity.getThumbnail(),
                entity.getCostPrice()
            ))
            .collect(Collectors.toList());
    }

}
